package com.yunduansing.demo.mapper;

import com.yunduansing.demo.entity.UserEntity;
import com.yunduansing.demo.model.user.UserDepartModel;
import com.yunduansing.demo.model.user.UserPageModel;
import com.yunduansing.demo.model.user.UserPageRequestModel;
import com.yunduansing.demo.model.user.UserPostModel;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yunduansing
 * @since 2020-05-24
 */
public interface UserMapper extends BaseMapper<UserEntity> {
/**
     * 插入
     * @param entity 用户实体
     * @return
     */
    @Insert("insert into sys_user(account,password,full_name,status,create_date,is_admin) values(#{entity.account}," +
            "#{entity.password},#{entity.fullName},#{entity.status},now(),#{entity.isAdmin})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Long create(@Param("entity") UserEntity entity);

    /**
     * 根据账号查找已存在的
     * @param account
     * @return
     */
    @Select("select * from sys_user where account=#{account} and status!=1")
    List<UserEntity> findExistsByAccount(@Param("account") String account);

    List<UserPageModel> getPage(UserPageRequestModel model);
    List<UserDepartModel> getDepartsByUserId(List<Integer> userIds);
    List<UserPostModel> getPostsByUserId(List<Integer> userIds);
}
